<%@ page language="java"  pageEncoding="utf-8"%>
<%@ page import="java.util.Vector,com.ejoysoft.wlanyz.business.Ap,com.ejoysoft.common.Constants,com.ejoysoft.common.exception.NoRightException" %>
<%@ include file="../include/jsp/head.jsp"%>
<%
if(!globa.userSession.hasRight("20005"))
      throw new NoRightException("用户不具备操作该功能模块的权限，请与系统管理员联系！");
%>
<%
    //初始化
    Ap  ap0=null;
    Ap obj=new Ap(globa);
    //查询条件
    String  HOTSPOT=ParamUtil.getString(request,"HOTSPOT","").trim();
    
    String  strApName=ParamUtil.getString(request,"strApName","").trim();
    String  strApIp=ParamUtil.getString(request,"strApIp","").trim();
    String exportFlag = ParamUtil.getString(request,"exportFlag","");
	String exportContent = ParamUtil.getString(request,"exportContent","");
		//当前页
    int intCurPage = Integer.parseInt(ParamUtil.getString(request,"strCurPage","1"));
	String tWhere=" WHERE 1=1";
    if(!HOTSPOT.equals("")){
     tWhere += " and a.HOTSPOT LIKE '%"+ HOTSPOT +"%'";
    }
    if(!strApName.equals("")){
     tWhere += " and a.DEVICE_NAME LIKE '%"+ strApName +"%'";     
    }
    if(!strApIp.equals("")){
     tWhere += " and a.IP_ADDR LIKE '%"+ strApIp +"%'";
    }
	//记录总数
	int intAllCount=obj.getCount(tWhere);	

	//每页记录数
	String strPageSize = ParamUtil.getString(request,"strPageSize","10");
    int intPageSize;
    if(strPageSize.equals("所有"))intPageSize = intAllCount;
      else  intPageSize = Integer.parseInt(strPageSize);
	//共有页数
 	int intPageCount=(intAllCount-1)/intPageSize+1;
	// 循环显示一页内的记录 开始序号
	int intStartNum=(intCurPage-1)*intPageSize+1;
	//结束序号
	int intEndNum=intCurPage*intPageSize;   
	//获取到当前页面的记录集
	Vector<Ap> vctObj=obj.list(tWhere,intStartNum,intPageSize);
	//获取当前页的记录条数
	int intVct=(vctObj!=null&&vctObj.size()>0?vctObj.size():0);
    
	if(exportFlag.equals("exportResult"))
	{
		if(exportContent.equals("allPage"))
		{
			vctObj=obj.list(tWhere,0,0);
		}
   	   	StringBuffer sb = new StringBuffer();
	    sb.append("城市,区县 ,热点,ap名称,信道质量,信号强度,信噪比\n");
	    if (vctObj.size() != 0)
	    {
		    for (int i = 0; i < vctObj.size(); i++)
		    {
		       String strSb = vctObj.get(i).getApCity().replace("\n","") + ",";
		       strSb += vctObj.get(i).getApCounty().replace("\n","") + ",";
		       strSb += vctObj.get(i).getHotSpot() + "," ;
		       strSb += vctObj.get(i).getApName() + "," ;
		       strSb += vctObj.get(i).getApQuality() + "," ;
		       strSb += vctObj.get(i).getApRssi() + "," ;
		       strSb += vctObj.get(i).getApRsn() + ",\n";
			   sb.append(strSb);
		    }
	    }
	    String strFileName = "ap无线查询表.csv";//自定义csv文件的文件名
	    response.setContentType("APPLICATION/*");
	    response.setHeader( "Content-Disposition", "attachment;filename="  + new String( strFileName.getBytes("gbk"), "ISO8859-1" ));
	    out.clearBuffer(); 
	    out = pageContext.pushBody();
	    ServletOutputStream output = response.getOutputStream();
	    output.write(sb.toString().getBytes());
 
	} 
%>
<%@ include file="../include/jsp/footer.jsp"%>
